// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   answerRegister_ok.java

package hr.engage.test;

import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class answerRegister_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;

	public answerRegister_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			java.io.PrintWriter out = response.getWriter();
			nseer_db_backup1 hr_db = new nseer_db_backup1(dbApplication);
			nseer_db_backup1 hr_db1 = new nseer_db_backup1(dbApplication);
			if (hr_db.conn((String)dbSession.getAttribute("unit_db_name")) && hr_db1.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				counter counta = new counter(dbApplication);
				String answer_id = "";
				String human_name = request.getParameter("human_name");
				String idcard = request.getParameter("idcard");
				String test_ID = request.getParameter("test_ID");
				String questiones_amount = request.getParameter("questiones_amount");
				String max_total_points = request.getParameter("max_total_points");
				String usedtime = request.getParameter("usedtime");
				String test_time = request.getParameter("test_time");
				int testing_ID = counta.read((String)dbSession.getAttribute("unit_db_name"), "hrTestingcount");
				counta.write((String)dbSession.getAttribute("unit_db_name"), "hrTestingcount", testing_ID);
				String sql9 = (new StringBuilder("insert into hr_tester(testing_ID,human_name,idcard,test_time,examtime,test_ID,max_total_points) values ('")).append(testing_ID).append("','").append(human_name).append("','").append(idcard).append("','").append(test_time).append("','").append(usedtime).append("','").append(test_ID).append("','").append(max_total_points).append("')").toString();
				hr_db.executeUpdate(sql9);
				String sql = (new StringBuilder("select * from hr_test_details where test_ID='")).append(test_ID).append("' order by id").toString();
				String sql2;
				for (ResultSet rs = hr_db1.executeQuery(sql); rs.next(); hr_db.executeUpdate(sql2))
				{
					answer_id = "";
					String temkind = (new StringBuilder("first_kind")).append(rs.getString("id")).toString();
					String temcount = (new StringBuilder("count")).append(rs.getString("id")).toString();
					String kind = request.getParameter(temkind);
					String count = request.getParameter(temcount);
					int amount = Integer.parseInt(count);
					for (int i = 1; i <= amount; i++)
					{
						String temanswer = (new StringBuilder(String.valueOf(rs.getString("id")))).append(i).toString();
						String answer1[] = request.getParameterValues(temanswer);
						String answer = "";
						if (answer1 != null)
						{
							for (int k = 0; k < answer1.length; k++)
								answer = (new StringBuilder(String.valueOf(answer))).append(answer1[k]).toString();

						} else
						{
							answer = "f";
						}
						answer_id = (new StringBuilder(String.valueOf(answer_id))).append(answer).append(",").toString();
					}

					sql2 = (new StringBuilder("insert into hr_tester_answer_details(testing_ID,human_name,idcard,test_ID,question_first_kind,answer_id_group) values ('")).append(testing_ID).append("','").append(human_name).append("','").append(idcard).append("','").append(test_ID).append("','").append(kind).append("','").append(answer_id).append("')").toString();
				}

				hr_db.commit();
				hr_db1.commit();
				hr_db.close();
				hr_db1.close();
				response.sendRedirect((new StringBuilder("hr/engage/test/answerRegister_ok_a.jsp?usedtime=")).append(toUtf8String.utf8String(exchange.toURL(usedtime))).toString());
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception exception) { }
	}
}
